package com.atguigu.gmall.order.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/***
 * 消息投递返回模式设置
 */
@Configuration
@Slf4j
public class RabbitReturnCallbackConfig {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 初始化完成后,配置return模式
     */
    @PostConstruct
    public void init(){
        rabbitTemplate.setReturnCallback((a,b,c,d,e)->{
            log.error("消息抵达队列失败,消息的内容为: " + new String(a.getBody()));
            log.error("消息抵达队列失败,消息的错误码为: " + b);
            log.error("消息抵达队列失败,消息的错误信息为: " + c);
            log.error("消息抵达队列失败,消息的交换机为: " + d);
            log.error("消息抵达队列失败,消息的routingKey为: " + e);
        });
    }
}
